﻿package { 

    import flash.display.MovieClip; 
    import flash.display.Sprite; 
    import flash.events.Event; 
	import flash.utils.Timer;

    public class Clock extends Sprite { 
	
	    public var ticker:Timer;
	 
		private const STAGE_CENTER_X:Number = stage.stageWidth / 2; 
		private const STAGE_CENTER_Y:Number = stage.stageHeight / 2; 

        private var clockMC:MovieClip 
		private var second_hand:Sprite; 
		private var minute_hand:Sprite; 
		private var hour_hand:Sprite; 
		private var center_pin:Sprite; 
		private var circle:Sprite; 
		private var three:Sprite; 
		private var six:Sprite;
		private var nine:Sprite;
		private var twe:Sprite; 

        private var base_color:uint = 0x000000; 
        private var rSeconds:Number; 
		private var rMinutes:Number; 
		private var rHours:Number; 
		private var onmArray:Array = []; 



        public function Clock() { 

            init(); 
			this.ticker = new Timer(1000);
			this.ticker.start();

        } 

        private function init():void { 

            clock(); 
            addEventListener(Event.ENTER_FRAME, main) 

        } 
		
//轉動指針
        private function main(eventObject:Event):void { 
		
		    var now_date:Date = new Date(); 
			
			second_hand.rotation = now_date.seconds * 6; 
            minute_hand.rotation = now_date.minutes * 6; 
            hour_hand.rotation = now_date.hours * 30 + now_date.minutes/2; 
			
			
			clockMC.x = STAGE_CENTER_X; 
			clockMC.y = STAGE_CENTER_Y; 

          
        } 

        

        private function clock():void { 
		clockMC = new MovieClip(); 
		addChild( clockMC ); 
			
//時鐘外框
            circle = new Sprite(); 
			circle.graphics.beginFill( 0xffffff ); 
			circle.graphics.lineStyle( 2, base_color ); 
			circle.graphics.drawCircle( 0, 0, 190); 
			circle.graphics.endFill(); 
			circle.x = 0; 
			circle.y = 0; 
			clockMC.addChild( circle ); 

           

            

//時針

            hour_hand = new Sprite(); 
			hour_hand.graphics.beginFill( 0x000000 ); 
			hour_hand.graphics.drawRect( -4, 0, 8, -100 ); 
			hour_hand.graphics.endFill(); 
			hour_hand.x = 0; 
			hour_hand.y = 0; 
			clockMC.addChild( hour_hand ); 


//分針
            minute_hand = new Sprite(); 
			minute_hand.graphics.beginFill( 0x000000 ); 
			minute_hand.graphics.drawRect( -2.5, 0, 5, -150 ); 
			minute_hand.graphics.endFill(); 
			minute_hand.x = 0; 
			minute_hand.y = 0; 
			clockMC.addChild( minute_hand ); 


//秒針


            second_hand = new Sprite(); 
			second_hand.graphics.lineStyle( 2, 0xff0000 ); 
			second_hand.graphics.moveTo( 0, 30 ); 
			second_hand.graphics.lineTo( 0, -156 ); 
			second_hand.x = 0; 
			second_hand.y = 0; 
			clockMC.addChild( second_hand ); 
			
			
//中心
            center_pin = new Sprite();
			center_pin.graphics.beginFill( 0xff0000 ); 
			center_pin.graphics.drawCircle( 0, 0, 8 ); 
			center_pin.graphics.endFill(); 
			center_pin.x = 0; 
			center_pin.y = 0; 
			clockMC.addChild( center_pin ); 
			
//3點		
			three = new Sprite();
			three.graphics.beginFill(0x000000 ); 
			three.graphics.drawCircle( 0, 0, 10 ); 
			three.graphics.endFill(); 
			three.x = 170; 
			three.y = 0; 
			clockMC.addChild(three); 
//6點			
			six = new Sprite();
			six.graphics.beginFill(0x000000 ); 
			six.graphics.drawCircle( 0, 0, 10 ); 
			six.graphics.endFill(); 
			six.x = 0; 
			six.y = 170; 
			clockMC.addChild(six); 
//9點			
			nine = new Sprite();
			nine.graphics.beginFill(0x000000 ); 
			nine.graphics.drawCircle( 0, 0, 10 ); 
			nine.graphics.endFill(); 
			nine.x -=170; 
			nine.y = 0; 
			clockMC.addChild(nine); 
//12點
			twe = new Sprite();
			twe.graphics.beginFill(0x000000 ); 
			twe.graphics.drawCircle( 0, 0, 10 ); 
			twe.graphics.endFill(); 
			twe.x = 0; 
			twe.y = -170; 
			clockMC.addChild(twe); 

        } 

    } 

} 



